package co.com.javeriana.aes.oms.menu;

import co.com.javeriana.aes.oms.constants.NavRules;
import co.com.javeriana.aes.oms.constants.Permissions;
import co.com.javeriana.aes.oms.util.Util;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Jonathan Fernandez <jonathan.fvargas@gmail.com>
 */
@ManagedBean(name = "menuView")
@SessionScoped
public class menuView implements java.io.Serializable {

    private boolean VIEW_PRODUCTS,
            ADMIN_PRODUCTS,
            CAMPANNAS,
            VIEW_ORDERS,
            ADMIN_ORDERS,
            VIEW_CLIENTS,
            ADMIN_CLIENTS,
            FULL_ACCESS;

    public boolean isVIEW_PRODUCTS() {
        return VIEW_PRODUCTS;
    }

    public void setVIEW_PRODUCTS(boolean VIEW_PRODUCTS) {
        this.VIEW_PRODUCTS = VIEW_PRODUCTS;
    }

    public boolean isADMIN_PRODUCTS() {
        return ADMIN_PRODUCTS;
    }

    public void setADMIN_PRODUCTS(boolean ADMIN_PRODUCTS) {
        this.ADMIN_PRODUCTS = ADMIN_PRODUCTS;
    }

    public boolean isCAMPANNAS() {
        return CAMPANNAS;
    }

    public void setCAMPANNAS(boolean CAMPANNAS) {
        this.CAMPANNAS = CAMPANNAS;
    }

    public boolean isVIEW_ORDERS() {
        return VIEW_ORDERS;
    }

    public void setVIEW_ORDERS(boolean VIEW_ORDERS) {
        this.VIEW_ORDERS = VIEW_ORDERS;
    }

    public boolean isADMIN_ORDERS() {
        return ADMIN_ORDERS;
    }

    public void setADMIN_ORDERS(boolean ADMIN_ORDERS) {
        this.ADMIN_ORDERS = ADMIN_ORDERS;
    }

    public boolean isVIEW_CLIENTS() {
        return VIEW_CLIENTS;
    }

    public void setVIEW_CLIENTS(boolean VIEW_CLIENTS) {
        this.VIEW_CLIENTS = VIEW_CLIENTS;
    }

    public boolean isADMIN_CLIENTS() {
        return ADMIN_CLIENTS;
    }

    public void setADMIN_CLIENTS(boolean ADMIN_CLIENTS) {
        this.ADMIN_CLIENTS = ADMIN_CLIENTS;
    }

    public boolean isFULL_ACCESS() {
        return FULL_ACCESS;
    }

    public void setFULL_ACCESS(boolean FULL_ACCESS) {
        this.FULL_ACCESS = FULL_ACCESS;
    }

    @PostConstruct
    public void render() {

        String userPermission = Util.getUserInSession().getUserPermission();

        switch (Permissions.valueOf(userPermission)) {

            case ADMIN_CLIENTS:

                ADMIN_CLIENTS = true;
                VIEW_CLIENTS = true;

                break;

            case ADMIN_ORDERS:

                ADMIN_ORDERS = true;
                VIEW_ORDERS = true;

                break;
            case ADMIN_PRODUCTS:

                ADMIN_PRODUCTS = true;
                VIEW_PRODUCTS = true;

                break;

            case CAMPANNAS:
                CAMPANNAS = true;
                break;
            case FULL_ACCESS:
                
                CAMPANNAS = true;
                ADMIN_PRODUCTS = true;
                VIEW_PRODUCTS = true;
                ADMIN_ORDERS = true;
                VIEW_ORDERS = true;
                ADMIN_CLIENTS = true;
                VIEW_CLIENTS = true;

                break;
            case VIEW_CLIENTS:
                VIEW_CLIENTS = true;
                break;
            case VIEW_ORDERS:

                VIEW_ORDERS = true;
                break;

            case VIEW_PRODUCTS:
                VIEW_PRODUCTS = true;
                break;
        }
    }

    public String toProducts() {
        return NavRules.GO_TO_PRODUCTS.name();
    }

    public String toCampaigns() {
        return NavRules.GO_TO_CAMPAIGNS.name();
    }
}
